import axios from 'axios'

const BASE_URL = process.env.VUE_APP_API_BASE_URL || 'http://localhost:8080'

// 模拟数据
const mockData = {
  movieDetail: {
    id: 1,
    name: '流浪地球',
    poster: 'https://p0.pipi.cn/mmdb/fb73862f7f1f9a05c8d3a5bd5b8a95c0d8e3d.jpg',
    score: 9.0,
    director: '郭帆',
    actors: '屈楚萧, 吴京',
    type: '科幻',
    duration: 160,
    language: '国语',
    dimension: '3D'
  },
  
  showtimeDetail: {
    id: 1,
    movieId: 1,
    hallName: '2号激光厅',
    startTime: '2024-01-20 14:30',
    endTime: '2024-01-20 17:10',
    language: '国语',
    dimension: '3D',
    price: 45.9
  },
  
  // 8x12的座位图，0表示可选，1表示已售
  seatMap: [
    [0,0,0,0,1,1,0,0,0,0,0,0],
    [0,0,0,1,0,0,1,0,0,0,0,0],
    [0,0,0,0,0,0,0,0,0,1,1,0],
    [0,1,1,0,0,0,0,0,0,0,0,0],
    [0,0,0,0,1,1,1,0,0,0,0,0],
    [0,0,0,0,0,0,0,0,1,0,0,0],
    [0,0,1,0,0,0,0,0,0,0,1,0],
    [0,0,0,0,1,1,0,0,0,0,0,0]
  ]
}

export const movieApi = {
  // 获取电影列表
  getMovies(type = 'now', page = 1) {
    return axios.get(`${BASE_URL}/api/movies/${type}`, {
      params: { page, limit: 12 }
    })
  },

  // 获取电影详情
  getMovieDetail(id) {
    // 返回模拟数据
    return Promise.resolve({
      data: mockData.movieDetail
    })
  },

  // 搜索电影
  searchMovies(keyword) {
    return axios.get('/movies/search', {
      params: { keyword }
    })
  },

  // 提交评分
  submitRating(movieId, score, comment) {
    return axios.post(`/movies/${movieId}/rating`, {
      score,
      comment
    })
  },

  // 获取场次信息
  getShowtimes(movieId, date) {
    return axios.get(`/movies/${movieId}/showtimes`, {
      params: { date }
    })
  },

  // 锁定座位
  lockSeats(showtimeId, seats) {
    // 模拟成功响应
    return Promise.resolve({
      data: { success: true }
    })
  },

  // 创建订单
  createOrder(showtimeId, seats) {
    // 模拟订单创建成功
    return Promise.resolve({
      data: {
        orderId: Date.now().toString(),
        showtimeId,
        seats,
        totalPrice: seats.length * mockData.showtimeDetail.price,
        createTime: new Date().toISOString()
      }
    })
  },

  // 获取场次详情
  getShowtimeDetail(showtimeId) {
    // 返回模拟数据
    return Promise.resolve({
      data: mockData.showtimeDetail
    })
  },

  // 获取座位图
  getSeatMap(showtimeId) {
    // 返回模拟数据
    return Promise.resolve({
      data: mockData.seatMap
    })
  }
} 